namespace practiceCourse3 {
  function minSubArrayLen(target: number, nums: number[]): number {
    let res = Infinity;
    let left = 0;
    let sum = 0;
    for (let right = 0; right < nums.length; right++) {
      sum += nums[right];
      while (sum >= target) {
        let curLen = right - left + 1;
        res = curLen < res ? curLen : res;
        sum -= nums[left++]
      }
    }
    return res === Infinity ? 0 : res;
  }
}